package com.big.codegen.controller;

import com.big.codegen.domain.dto.DatasourceDTO;
import com.big.codegen.domain.entity.Datasource;
import com.big.codegen.service.DatasourceService;
import com.big.codegen.util.DatabaseUtils;
import com.big.common.core.result.Result;
import com.big.common.mybatis.base.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据源Controller
 *
 * @author 山归岿
 * @create 2025-01-03
 */
@Slf4j
@RestController
@RequestMapping("/datasource")
@Tag(name = "数据源管理", description = "数据源相关接口")
public class DatasourceController extends BaseController<DatasourceDTO, Datasource, DatasourceService> {

    public DatasourceController(DatasourceService service) {
        super(service);
    }

    @Operation(summary = "测试连接")
    @PostMapping("/testConnection")
    public Result<Boolean> testConnection(@Valid @RequestBody DatasourceDTO dto) {
        return Result.ok(DatabaseUtils.testConnection(dto));
    }

}